//判断设备函数
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}
//联系我们弹出框
function contact(){
    $('.mask-bg').css({'visibility':'visible','opacity':'1'});
    setTimeout(function(){
        $('.modal1').css({'transform':'translateY(50px)','visibility':'visible','opacity':'1'});
    },200)
}
//成为大腕弹出框
function tobe_star(){
    $('.mask-bg').css({'visibility':'visible','opacity':'1'});
    setTimeout(function(){
        $('.modal2').css({'transform':'translateY(50px)','visibility':'visible','opacity':'1'});
    },200)
}
//提交 联系我们数据
function mySubmit1(){
    var tel = $('#tel1').val().trim();
    var msg = $('#message').val().trim();
    if(tel==''|| tel==null){
        $('#tel1').focus();
        return
    }
    if(msg==''|| msg==null){
        $('#message').focus();
        return
    }
    $('.m_btn1').removeAttr(onclick);
    $.ajax({
        url:'php/index.php',
        type:'post',
        data:{
            'tel':tel,
            'msg':msg
        },
        success:function(data){
            $('#tel1').val("");
            $('#message').val("");
            closeModal();
            $('.m_btn1').attr('onclick','mySubmit1()')
        },
        error:function(data){
            alert('提交失败，请稍后再试。');
            $('.m_btn1').attr('onclick','mySubmit1()')
        }
    })
}
//提交成为大腕数据
function mySubmit2(){
    var myname = $('#name').val().trim();
    var tel = $('#tel2').val().trim();
    var address = $('#address').val().trim();
    var suggestion = $('#suggestion').val().trim();
    if(myname==''|| myname==null){
        $('#name').focus();
        return
    }
    if(tel==''|| tel==null){
        $('#tel2').focus();
        return
    }
    if(address==''|| address==null){
        $('#address').focus();
        return
    }
    if(suggestion==''|| suggestion==null){
        $('#suggestion').focus();
        return
    }
    $('.m_btn2').removeAttr(onclick);
    $.ajax({
        url:'php/tobeStar.php',
        type:'post',
        data:{
            'name':myname,
            'tel':tel,
            'address':address,
            'suggestion':suggestion
        },
        success:function(data){
            $('#name').val("");
            $('#tel2').val("");
            $('#address').val("");
            $('#suggestion').val("");
            closeModal();
            $('.m_btn2').attr('onclick','mySubmit2()');
        },
        error:function(data){
            alert('提交失败，请稍后再试。');
            $('.m_btn2').attr('onclick','mySubmit2()');
        }
    })
}
//关闭弹出框
function closeModal(){
    $('.modal').css({'transform':'translateY(0px)','visibility':'hidden','opacity':'0'});
    $('.mask-bg').css({'visibility':'hidden','opacity':'0'});
}
//加载完成
window.onload = function(){
    var isPC = IsPC();
    var bg = parseInt(Math.random()*23)+1;
    $('body').css('background-image','url("img/bg'+bg+'.png")');

    if(isPC){
        $('.mask').css({'visibility':'hidden','opacity':'0'});
        $('.footer').addClass('slideUp');
        setTimeout(function(){
            $('.img2').css({'visibility':'visible','opacity':'1'});
        },500);
        setTimeout(function(){
            $('.img1').addClass('mySlideRight');
        },1300);
        setTimeout(function(){
            $('.img3').addClass('mySlideLeft');
        },1400);
        setTimeout(function(){
            $('.logo').addClass('fadeIn');
        },2400);
        setTimeout(function(){
            $('.left-btn').addClass('mySlideRight2');
            $('.right-btn').addClass('mySlideLeft2');
        },3800);
        $(' .bottoms .btn').hover(
            function(){
                $(this).find('.code').addClass('expandUp');
            });
    }else{
        window.location.href = 'wap/index.html';
    }
    setInterval(function(){
        var bg1 = parseInt(Math.random()*23)+1;
        $('.lazy-img').css('background-image','url("img/bg'+bg1+'.png")');
        setTimeout(function(){
            $('body').css('background-image','url("img/bg'+bg1+'.png")');
        },9000)
    },10000);
};